package com.battle.service.controller.web;

import com.battle.pojo.param.personCallRecord.ImportPersonCallRecordParam;
import com.battle.pojo.param.trainingAchievement.*;
import com.battle.pojo.param.userAttention.CreateUserAttentionParam;
import com.battle.pojo.vo.trainingAchievement.*;
import com.battle.service.service.in.*;
import com.battle.service.utils.FileUtil;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * web/培训成绩
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/trainingAchievement/web")
public class TrainingAchievementWebController {

    private final TrainingAchievementService service;

    public TrainingAchievementWebController(TrainingAchievementService service) {
        this.service = service;
    }

    /**
     * 创建培训成绩
     *
     * @param param
     * @return
     */
    @PostMapping("/createTrainingAchievement")
    public ApiResult createTrainingAchievement(@RequestBody @Valid CreateTrainingAchievementParam param) {
        service.createTrainingAchievement(param);
        return ApiResult.ok();
    }

    /**
     * 修改培训成绩
     *
     * @param param
     * @return
     */
    @PostMapping("/editTrainingAchievement")
    public ApiResult editTrainingAchievement(@RequestBody @Valid EditTrainingAchievementParam param) {
        service.editTrainingAchievement(param);
        return ApiResult.ok();
    }

    /**
     * 获取培训成绩详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getTrainingAchievement")
    public ApiResult<GetTrainingAchievementVo> getTrainingAchievement(@RequestParam("id") Long id) {
        GetTrainingAchievementVo vo = service.getTrainingAchievement(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取培训成绩列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getTrainingAchievementList")
    public ApiResult<PageResult<GetTrainingAchievementListVo>> getTrainingAchievementList(@RequestBody GetTrainingAchievementListParam param) {
        PageResult<GetTrainingAchievementListVo> result = service.getTrainingAchievementList(param);
        return ApiResult.ok(result);
    }

    /**
     * 下载模板
     *
     * @param response
     */
    @PostMapping(value = "/downTemplate")
    public void downTemplate(HttpServletResponse response) {
        //模板名称
        String fileName = "trainingAchievement.xlsx";
        FileUtil.downloadFile(response, fileName);
    }


    /**
     * 导入考核成绩
     * @param param
     */
    @PostMapping("/importTrainingAchievement")
    public ApiResult importTrainingAchievement(@RequestBody ImportTrainingAchievementParam param) throws IOException {
        service.importTrainingAchievement(param);
        return ApiResult.ok();
    }
}

